package com.example.service.impl;

import com.example.common.Page;
import com.example.common.PageQueryParam;
import com.example.dao.TCommentMapper;
import com.example.dto.CommentDto;
import com.example.entity.TCommentEntity;
import com.example.service.TCommentService;
import com.example.vo.CommentVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service("tCommentService")
public class TCommentServiceImpl implements TCommentService {

    @Autowired
    TCommentMapper tCommentMapper;

    @Override
    public Page<CommentVo> query(PageQueryParam<TCommentEntity> pageQueryParam) {
        Integer total = tCommentMapper.count();
        List<CommentVo> rows = new ArrayList<>();
        rows = tCommentMapper.select(pageQueryParam);
        Page<CommentVo> page = new Page<>();
        page.setTotal(total);
        page.setRows(rows);
        return page;
    }

    @Override
    public Integer create(CommentDto commentDto) {
        commentDto.setDateTime(new Date());
        Integer status = tCommentMapper.create(commentDto);
        return status;
    }

    @Override
    public Integer delete(CommentDto commentDto) {
        return tCommentMapper.delete(commentDto.getId());
    }
}